<?php
/**
* @file $Id: Transcripts.php 649 2007-09-15 01:09:39Z ryness $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

$user_school = UserSchool();

$custom_fields = DBGetRow("
SELECT       ( SELECT       'CUSTOM_' || cf.id as VALUE
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'Birthdate' )        as BIRTH_DATE
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ACT English')       as ACT_ENGLISH
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ACT Math')          as ACT_MATH
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ACT Reading')       as ACT_READING
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ACT Science')       as ACT_SCIENCE
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ACT Composite')     as ACT_COMPOSITE
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ACT English/Writing') as ACT_ENG_WRIT
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ACT Writing')       as ACT_WRITING
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ACT Test Date')     as ACT_TEST_DATE
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'SAT  Writing')        as SAT_WRITING
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'SAT Multiple Choice') as SAT_MULT_CHOICE
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'SAT Mathematics')     as SAT_MATH
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = ' SAT Verbal/Critical Reading') as SAT_READING
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'SAT Essay')           as SAT_ESSAY
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'SAT Test Date')       as SAT_TEST_DATE
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ISAT Mathmatics')   as ISAT_MATH
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ISAT Reading')      as ISAT_READING
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ISAT Language Usage') as ISAT_LANGUAGE
 ,           ( SELECT       'CUSTOM_' || cf.id as COLUMN_ID
			   FROM         CUSTOM_FIELDS cf
			   WHERE        cf.TITLE = 'ISAT Science')      as ISAT_SCIENCE 
        ");
        
$extra['SELECT'] = "
 ,           s.$custom_fields[BIRTH_DATE]             as BIRTH_DATE
 ,           ( SELECT    gl.TITLE 
			   FROM      SCHOOL_GRADELEVELS gl
				,        STUDENT_ENROLLMENT se
			   WHERE     se.STUDENT_ID = s.STUDENT_ID
				AND      se.GRADE_ID = gl.ID
			   ORDER BY  gl.SORT_ORDER DESC
			   LIMIT 1 )                              as CURRENT_GRADE_LEVEL
 ,           s.$custom_fields[ACT_ENGLISH]            as ACT_ENGLISH
 ,           s.$custom_fields[ACT_MATH]               as ACT_MATH
 ,           s.$custom_fields[ACT_READING]            as ACT_READING
 ,           s.$custom_fields[ACT_SCIENCE]            as ACT_SCIENCE
 ,           s.$custom_fields[ACT_COMPOSITE]          as ACT_COMPOSITE
 ,           s.$custom_fields[ACT_ENG_WRIT]           as ACT_ENG_WRIT
 ,           s.$custom_fields[ACT_WRITING]            as ACT_WRITING
 ,           to_char(s.$custom_fields[ACT_TEST_DATE], 'MM/YY') as ACT_TEST_DATE
 ,           s.$custom_fields[SAT_WRITING]            as SAT_WRITING
 ,           s.$custom_fields[SAT_MULT_CHOICE]        as SAT_MULT_CHOICE
 ,           s.$custom_fields[SAT_MATH]               as SAT_MATH
 ,           s.$custom_fields[SAT_READING]            as SAT_READING
 ,           s.$custom_fields[SAT_ESSAY]              as SAT_ESSAY
 ,           to_char(s.$custom_fields[SAT_TEST_DATE], 'MM/YY')  as SAT_TEST_DATE
 ,           s.$custom_fields[ISAT_MATH]              as ISAT_MATH
 ,           s.$custom_fields[ISAT_READING]           as ISAT_READING
 ,           s.$custom_fields[ISAT_LANGUAGE]          as ISAT_LANGUAGE
 ,           s.$custom_fields[ISAT_SCIENCE]           as ISAT_SCIENCE
 ,           gpa.CUMULATIVE_GPA                       as CUMULATIVE_GPA
 ,           TO_CHAR(gpa.CUMULATIVE_CREDITS, '99.9')  as CUMULATIVE_CREDITS
 ,           TO_CHAR( 
					( SELECT sum(CREDITS) 
					  FROM student_report_card_grades srcg
			          WHERE srcg.STUDENT_ID = s.STUDENT_ID
			          AND srcg.CREDITS > 0
					  AND srcg.CARRIES_CREDITS = 'Y'
                      AND srcg.AFFECTS_GPA = 'Y'
					  AND SCHOOL_ID = '$user_school')
					, '99.9')                         as EXPECTED_CUMULATIVE_CREDITS
 ,           gpa.GRADE_TOTAL                          as CLASS_SIZE
 ,           gpa.CLASS_RANK                           as CLASS_RANK";

$extra['FROM'] = "
 ,           STUDENT_GPA_CALCULATED gpa";

$extra['WHERE'] = "
 AND         s.STUDENT_ID = gpa.STUDENT_ID";

$extra['ORDER'] = "
 ,           s.LAST_NAME
 ,           s.FIRST_NAME";

Widgets('all');
         
$extra['action'] .= "&_FOCUS_PDF=true";
$extra['force_search'] = true;

if (!$_REQUEST['search_modfunc'] 
||   $_REQUEST['search_modfunc'] == 'search' 
||   $_FOCUS['modules_search']
){
    DrawHeader(ProgramTitle());

    $extra['new'] = true;
    Search('student_id', $extra);
}
else {
    $students_RET = GetStuList($extra);
	
	// check to see if calcgpa needs to be run 
    foreach ($students_RET as $student_ROW) {
		if ($student_ROW['CUMULATIVE_CREDITS'] != $student_ROW['EXPECTED_CUMULATIVE_CREDITS']) {
			die("
<html>
<body>
You need to 
<a href='./Modules.php?modname=Grades/CalcGPA.php'> Rebuild </a> 
the GPA / Class Rank table!
<br/>
Cumulative credits are not adding up as they should.
<!-- $student_ROW[FULL_NAME] : $student_ROW[STUDENT_ID]
$student_ROW[CUMULATIVE_CREDITS] != $student_ROW[EXPECTED_CUMULATIVE_CREDITS]
-->
</body>
</html>
				");
		}		
	}
	
    $user_school = UserSchool();
	$school_logo = $staticpath . "assets/SchoolLogos/$user_school-96x96";

    $school_ROW = DBGetRow("
SELECT       sch.ID as SCHOOL_ID
 ,           sch.TITLE as SCHOOL_NAME
 ,           sch.ADDRESS
 ,           sch.CITY
 ,           sch.STATE
 ,           sch.ZIPCODE as ZIP
 ,           '(' || sch.AREA_CODE || ') '
			 || SUBSTRING(TO_CHAR(sch.PHONE, '9999999') from 1 for 4) 
			 || '-' 
			 || SUBSTRING(TO_CHAR(sch.PHONE, '9999999') from 5 for 4) 
					as PHONE
FROM         SCHOOLS sch
WHERE        sch.ID = '$user_school'
        ");
        

    $pdf_handle = PDFStart("--webpage --quiet -t pdf12 --no-links --footer ... "
                            ."--header ... --left 0.4in --top 0.4in --bottom 0 " 
                            . SystemPreferences("pdf_options", "grades"));
//echo "<html><body>";

    foreach ($students_RET as $student_ROW) {
        echo "
<table>
    <tr>";
		
		//if they want to use the school-logo feature, it will resize the logo to be 64x64, so make it that size
		if (file_exists("$school_logo.png")) {
			echo "
		<td rowspan='2' align='left' width='104'>
			<img src='$school_logo.png' height='96' width='96'>
		</td>";
		}
		elseif (file_exists("$school_logo.gif")) {
			echo "
		<td rowspan='2' align='left' width='104'>
			<img src='$school_logo.gif' height='96' width='96'>
		</td>";
		}
		elseif (file_exists("$school_logo.jpg")) {
			echo "
		<td rowspan='2' align='left' width='104'>
			<img src='$school_logo.jpg' height='96' width='96'>
		</td>";
		}
		
		echo "
        <td colspan='3'><center>
            <h1>$school_ROW[SCHOOL_NAME]</h1></center>
        </td>
    </tr>
    <tr>
        <td valign='top' nowrap  width='35%'>    
            " . _('Student Name') . ": <strong>$student_ROW[FULL_NAME]</strong><br />
            " . _('Birth Date') . ": $student_ROW[BIRTH_DATE] <br />
            " . _('Grade Level') .": $student_ROW[CURRENT_GRADE_LEVEL] 
        </td>    
        <td valign='top' align='center' width ='35%'>
            <h3>OFFICIAL TRANSCRIPT</h3>            
        </td>
        <td valign='top' align='" . ALIGN_RIGHT . "' nowrap width='35%'>
            $school_ROW[ADDRESS]<br />
            $school_ROW[CITY],
            $school_ROW[STATE]
            $school_ROW[ZIP]<br />
            <em>$school_ROW[PHONE]</em>
        </td>
    </tr>
</table>
        <td colspan='3'><hr width='80%' /></td>
<table>
    <tr>";
	
		//make sure each student gets completely clean data as thier start point
		unset($lines_needed_for_year);
		unset($lines_needed_for_mp);
		unset($mp_to_syear);
        unset($max_lines_per_col);
		unset($year_cols);
        $courses_by_marking_period_RET = DBGet(DBQuery("
SELECT       grd.MARKING_PERIOD_ID || '-' || grd.LOCATION_TITLE  as MARKING_PERIOD
 ,           grd.SYEAR                             as MARKING_PERIOD_YEAR
 ,           syr.SHORT_NAME                        as SCHOOL_YEAR_NAME
 ,           grd.LOCATION_TITLE                    as SCHOOL_NAME
 ,           sch.TITLE                             as THIS_SCHOOL_NAME
 ,           CASE 
			  WHEN qtr.MARKING_PERIOD_ID is NOT NULL
			   THEN qtr.TITLE
			  WHEN sem.MARKING_PERIOD_ID is NOT NULL
			   THEN sem.TITLE
			  WHEN yrs.MARKING_PERIOD_ID is NOT NULL
			   THEN yrs.TITLE
			  ELSE to_char(grd.SYEAR, '9999')
			 END                                   as MARKING_PERIOD_NAME
 ,           grd.COURSE_TITLE                      as COURSE_NAME
 ,           TO_CHAR(grd.CREDITS, '9.9')           as COURSE_CREDITS
 ,           grd.GRADE_TITLE                       as COURSE_GRADE
 ,           to_char(grd.GPA_POINTS, '9.9')        as COURSE_POINTS
FROM         STUDENT_REPORT_CARD_GRADES grd
 LEFT JOIN   SCHOOL_QUARTERS qtr
  ON         qtr.MARKING_PERIOD_ID = grd.MARKING_PERIOD_ID
 LEFT JOIN   SCHOOL_SEMESTERS sem
  ON         sem.MARKING_PERIOD_ID = grd.MARKING_PERIOD_ID
 LEFT JOIN   SCHOOL_YEARS yrs
  ON         yrs.MARKING_PERIOD_ID = grd.MARKING_PERIOD_ID
 JOIN        SCHOOLS sch
  ON         sch.ID = grd.SCHOOL_ID
 JOIN        SCHOOL_YEARS syr
  ON         syr.SCHOOL_ID = grd.SCHOOL_ID 
   and       syr.SYEAR = grd.SYEAR
WHERE        grd.STUDENT_ID = $student_ROW[STUDENT_ID]
 AND         grd.SCHOOL_ID = '$user_school'
 AND NOT     grd.COURSE_TITLE LIKE '%Released Time%'
ORDER BY     grd.SYEAR desc
 ,           qtr.SORT_ORDER desc
 ,           sem.SORT_ORDER desc
 ,           yrs.SORT_ORDER desc
        "), array(), array('MARKING_PERIOD'));
                
        $year_index = 0; //after year_index 2, we need a column break;
        $last_year = 0;
        
        // before we act, lets figure out the size of each syear, so we can lay them out intelligently
        foreach ($courses_by_marking_period_RET as $courses_RET) {			
            // store some conveneint values while we are adding things up.
            $syear_x = $courses_RET[1]['SCHOOL_YEAR_NAME'];
            $mp_x = $courses_RET[1]['MARKING_PERIOD'];
            $mp_to_syear[$mp_x] = $syear_x; //quick lookup table

            // the marking period is 2 lines for the header, and 1 for each row
            $lines_needed_for_mp[$mp_x] = 2 + count($courses_RET);

            //the year header is about 2 worth lines of overhead, add it to the first mp for the year
            if (! isset($lines_needed_for_year[$syear_x]) ) {
                $lines_needed_for_year[$syear_x] = 0; // we add more later
                $lines_needed_for_mp[$mp_x] += 2;
            }
                        
            // the year needs enough room for each marking period inside of it
            $lines_needed_for_year[$syear_x] += $lines_needed_for_mp[$mp_x];

			echo "
<!-- 
	syear_x = $syear_x
	mp_x = $mp_x
	mp_to_syear[$mp_x] = $mp_to_syear[$mp_x]
	lines_needed_for_year[$syear_x] = $lines_needed_for_year[$syear_x]
	lines_needed_for_mp[$mp_x] = $lines_needed_for_mp[$mp_x]  
--> ";
            
            // we dont need these anymore
            unset($mp_x);
            unset($syear_x);
        }
        
        //now we know how many rows each year will need, and we need to decide what
        //years will be the "new column" years, and wether or not we will need
        //to ultimately have 2 pages in order to do it right
        $page_count = 1;
        $cur_col = 1;
        $cur_row_count = 0;
        $max_lines_per_col[1] = 30;
        $max_lines_per_col[2] = 46;
        $max_lines_per_col[3] = 18;
        
        foreach ($lines_needed_for_year as $syear_x => $year_lines_x) {    
			// see if there is enough room on this column for the year in question
			if ($cur_row_count + $year_lines_x > $max_lines_per_col[$cur_col]) {
				$cur_col += 1;
				$cur_row_count = 0;
			}
			
			$year_cols[$syear_x] = $cur_col;
			$cur_row_count += $year_lines_x;

			echo "
<!-- 
	year_lines_x = $year_lines_x
	year_cols[$syear_x] = $year_cols[$syear_x]
	cur_row_count = $cur_row_count
-->";
			
            if ($cur_col > 3) {
                break;
            }
        }
        
        if ($cur_col > 3) {
			//we have a two pager     
			// lets try this again, and see if we can fit it all in.
            unset ($max_lines_per_col);
            $page_count = 2;
            $cur_col = 1;
            $cur_row_count = 0;
            $max_lines_per_col[1] = 45;
            $max_lines_per_col[2] = 45;
            $max_lines_per_col[3] = 45;
            $max_lines_per_col[4] = 30;
            $max_lines_per_col[5] = 43;
            $max_lines_per_col[6] = 18;
            
            foreach ($lines_needed_for_year[$syear] as $syear_x => $year_lines_x) {    
				// see if there is enough room on this column for the year in question
                if ($cur_row_count + $year_lines_x > $max_lines_per_col[$cur_col]) {
                    $cur_col += 1;
                    $cur_row_count = 0;
                }
                
                $year_cols[$syear_x] = $cur_col;
                $cur_row_count += $year_lines_x;

				echo "
<!-- 
	year_cols[$syear_x] = $year_cols[$syear_x]
	cur_row_count = $cur_row_count
-->";
                if ($cur_col > 6) {
                    break;
                }
            }
        }
        // now,  $year_cols[$mp_id] tells us which column we should be in while we print.
        
        $cur_col = 0;        
		$last_syear = '0';
        foreach ($courses_by_marking_period_RET as $courses_RET) {
			echo "
<!-- 
	year_cols['" . $courses_RET[1]['SCHOOL_YEAR_NAME'] ."'] = "
	. $year_cols[$courses_RET[1]['SCHOOL_YEAR_NAME']] . " 
-->";
			
            if ($year_cols[$courses_RET[1]['SCHOOL_YEAR_NAME']] != $cur_col) {
                $cur_col = $year_cols[$courses_RET[1]['SCHOOL_YEAR_NAME']];
                switch ($cur_col) {
                case 1:
                    if ($page_count == 1) {
                        echo "
        <td valign='top' align='center' rowspan='2' width='35%'>";
                    }
                    else {
                        echo "
        <td valign='top' align='center'>";
                    }
                    break;
                
                case 2:
                    if ($page_count == 1) {
                        echo "
        </td>
        <td valign='top' align='center' rowspan='3' width='35%'>";
                    }
                    else {
                        echo "
        </td>
        <td valign='top' align='center'>";
                    }
                    break;

                    break;

                case 3:
                    if ($page_count == 1) {
                        echo "
        </td>
        <td valign='top' align='center' rowspan='1' height='50%'  width='35%'>";
                    }
                    else {
                        echo "
        </td>
        <td valign='top' align='center'>";
                    }
                    break;
                
                case 4:
                    echo "
        </td>
    </tr>
</table>
<!-- NEW PAGE -->
<table>
    <tr>
        <td valign='top' align='center' rowspan='2' width='35%'>";
                    break;
                
                case 5:
                    echo "
        </td>
        <td valign='top' align='center' rowspan='3' width='35%'>";
                    break;
                    
                case 6:
                        echo "
        </td>
        <td valign='top' align='center' rowspan='1' height='50%' width='35%'>";
                    break;
                }                
            }

			if ($courses_RET[1]['SCHOOL_YEAR_NAME'] != $last_syear)
			{
				$last_syear = $courses_RET[1]['SCHOOL_YEAR_NAME'];
				echo "
            <strong>
				--- " . $courses_RET[1]['SCHOOL_YEAR_NAME'] . " ---
            </strong>";
			}
			
            echo "
			<small>
            <table>";
			
				if ($courses_RET[1]['SCHOOL_NAME'] != $courses_RET[1]['THIS_SCHOOL_NAME']) {
			echo "
               <tr>
                    <td align='center' colspan='5' nowrap><strong>
                        ***" . $courses_RET[1]['SCHOOL_NAME'] . "***
                    </strong></td>
                </tr>";
				}
			
			echo "
               <tr>
                    <td colspan='2' nowrap><strong><u>
                        " . $courses_RET[1]['SCHOOL_YEAR_NAME'] . " :
                        " . $courses_RET[1]['MARKING_PERIOD_NAME'] . "
                    </u></strong></td>
                    <td><u>" . _('Credits') . "</u></td>
                    <td colspan='2' align='" . ALIGN_RIGHT . "'><u>" . _('Grade') . "</u></td>
                </tr>";
    
            foreach ($courses_RET as $course_ROW) {
                echo "
                <tr>
                    <td>&nbsp;</td>
                    <td>$course_ROW[COURSE_NAME]</td>
                    <td align='center'>$course_ROW[COURSE_CREDITS]</td>
                    <td>$course_ROW[COURSE_GRADE]</td>
                    <td align='" . ALIGN_RIGHT . "'>$course_ROW[COURSE_POINTS]</td>
                </tr>";          
            }
                
            echo "
                <tr>
                    <th width='4em'><small><small>&nbsp;</small></small></th>
                    <th><small><small>&nbsp;</small></small></th>
                    <th width='3em'><small><small>&nbsp;</small></small></th>
                    <th width='3em'><small><small>&nbsp;</small></small></th>
                    <th width='4em'><small><small>&nbsp;</small></small></th>
                </tr>
            </table></small>";
            
        }
        
        // set the current column to 1/2/3 instead of 4/5/6
        while ($cur_col > 3) {
            $cur_col = $cur_col - 3;
        }
        
        // build the rest of the table columns so we dont have layout issues
        if ( $cur_col < 1 ) {
            echo "
        <td valign='top' align='center' rowspan='2' width='35%'>";
        }    

        if ( $cur_col < 2 ) {
            echo "
        </td>
        <td valign='top' align='center' rowspan='3' width='35%'>";
        }    
        if ( $cur_col < 3 ) {
            echo "
        </td>
        <td valign='top' align='center' rowspan='1' height='50%' width='35%'>
            <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
            <br /><br /><br /><br /><br /><br />";
        }    
            
        echo "
        </td>
    </tr>    
    <tr>
        <td valign='top' align='center' rowspan='2'><small>
            <table>    
                <tr>
                    <td colspan='3' align='center'>
                        <big><strong>--- Test Scores ---</strong></big>
                    </td>
                </tr>
                <tr>
					<td>ACT</td>
                    <td>English:</td>
                    <td>$student_ROW[ACT_ENGLISH]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Math:</td>
                    <td>$student_ROW[ACT_MATH]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Reading:</td>
                    <td>$student_ROW[ACT_READING]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Science:</td>
                    <td>$student_ROW[ACT_SCIENCE]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Composite:</td>
                    <td>$student_ROW[ACT_COMPOSITE]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>English/Writing:</td>
                    <td>$student_ROW[ACT_ENG_WRIT]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Writing:</td>
                    <td>$student_ROW[ACT_WRITING]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Test Date:</td>
                    <td>$student_ROW[ACT_TEST_DATE]</td>
                </tr>
                <tr><td><b>SAT</b></td>
                    <td>Writing:</td>
                    <td>$student_ROW[SAT_WRITING]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Multiple Choice:</td>
                    <td>$student_ROW[SAT_MULT_CHOICE]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Mathematics:</td>
                    <td>$student_ROW[SAT_MATH]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Verbal/Critical Reading:</td>
                    <td>$student_ROW[SAT_READING]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Essay:</td>
                    <td>$student_ROW[SAT_ESSAY]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Test Date:</td>
                    <td>$student_ROW[SAT_TEST_DATE]</td>
                </tr>    
                <tr><td><b>ISAT</b></td>
                    <td>Mathmatics:</td>
                    <td>$student_ROW[ISAT_MATH]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Reading:</td>
                    <td>$student_ROW[ISAT_READING]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Language Usage:</td>
                    <td>$student_ROW[ISAT_LANGUAGE]</td>
                </tr>    
                <tr><td>&nbsp;</td>
                    <td>Science:</td>
                    <td>$student_ROW[ISAT_SCIENCE]</td>
                </tr>    
            </table></small>
            <br />
        </td>
    </tr>
    <tr>
        <td valign='bottom' align='center' rowspan='2'>
            <hr width='80%' />
            <table>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td colspan='2' align='center'>
                        <strong>--- Summary ---</strong>
                    </td>
                </tr>
                <tr>
                    <td>". _('Cumulative Credits') . ": </td>
                    <td>$student_ROW[CUMULATIVE_CREDITS]</td>
                </tr>    
                <tr>
                    <td>" . _('Cumulative GPA') . ": </td>
                    <td>$student_ROW[CUMULATIVE_GPA]</td>
                </tr>    
                <tr>
                    <td>" . _('Class Rank') . ": </td>
                    <td>$student_ROW[CLASS_RANK] of $student_ROW[CLASS_SIZE]</td>
                </tr>    
                <tr>
                    <td>" . _('Graduation Date') . ": </td>
                    <td>...</td>
                </tr>    
            </table>
        </td>
    </tr>
    <tr>
        <td colspan='2' align='right'>
            <table>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td>_______________________________________</td>
                    <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                    <td>_______________</td>
                </tr>
                <tr>
                    <td><center><small><small><small>
                        ( Authorized Signiture )
                        </small></small></small></center>
                    </td>
                    <td><small><small><small>&nbsp;</small></small></small></td>
                    <td><center><small><small><small>
                        ( Date )
                        </small></small></small></center>
                    </td>
                </tr>
            </table>    
        </td>
    </tr>
</table>
<!-- NEW PAGE -->";

    }
    
    PDFStop($pdf_handle);
//echo "</body></html>";

}        

?>